home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
dev
/
c
/
cxref_1_4a.lha
/
parse.l
< prev
next >
Wrap
Text File
|
1997-12-07
|
22KB
|
425 lines
W [ \t]
N \r*\n
D [0-9]
L [a-zA-Z_]
H [a-fA-F0-9]
E [Ee][+-]?{D}+
FS (f|F|l|L)
IS (u|U|l|L)*
%x START_COMMENT COMMENT SPECIAL_COMMENT
%x START_COMMENT_CPP COMMENT_CPP SPECIAL_COMMENT_CPP
%x CPP CPP_START
%x CPP_INCLUDE CPP_INC_FILE CPP_INC_FLAGS
%x CPP_DEFINE CPP_DEFINE_ARGP CPP_DEFINE_BODY CPP_DEFINE_ARGS
%x GNU_LABEL GNU_ATTRIBUTE GNU_EXTENSION GNU_TYPEOF
%{
/***************************************
$Header: /home/amb/cxref/RCS/parse.l 1.23 1997/11/20 19:57:40 amb Exp $
C Cross Referencing & Documentation tool. Version 1.4a.
C lexical analyser
CPP processing, including GNU extensions, using yylval as a string.
******************/ /******************
Written by Andrew M. Bishop
This file Copyright 1995,96,97 Andrew M. Bishop
It may be distributed under the GNU Public License, version 2, or
any higher version. See section COPYING of the GNU Public license
for conditions under which this file may be redistributed.
***************************************/
#include "parse-yy.h"
#include "parse-yacc.h"
#include "cxref.h"
#include "memory.h"
/*+ The name of the current file. +*/
char* parse_file=NULL;
/*+ The current line number in the file. +*/
int parse_line=0;
/*+ If we are in a header file then ignore the comments. +*/
extern int in_header;
/*+ One of the options controlling how comments are processed, +*/
extern int option_all_comments, /*+ use all comments not just the specially formattted ones. +*/
option_block_comments, /*+ remove the leading block comment marker. +*/
option_no_comments; /*+ ignore all comments. +*/
/*+ Flag that indicates if the comment warnings are to be issued. +*/
extern int option_warn;
/*+ The flags that come out of GCC when a file is included. +*/
static int inc_file_flags=0;
/*+ The value of the thing that is defined (but only if it is simple). +*/
static char* define_value=NULL;
/*+ The lex state at the time that a comment is seen. +*/
static int comment_init_state=INITIAL;
/*+ To get around the GCC __attribute__ keyword, skip over matched () counted by this. +*/
static int gnu_att_depth=0;
/*+ To get around the GCC __typeof__ keyword, skip over matched () counted by this. +*/
static int gnu_typ_depth=0;
/*+ If we see a comment immediately after a ',', ';', '};', '},' or ')' then push it before. +*/
static int push_past=0;
/*++++++++++++++++++++++++++++++++++++++
Reset the Lexer, ready for the next file.
++++++++++++++++++++++++++++++++++++++*/
void ResetLexer(void)
{
parse_file=NULL;
parse_line=0;
inc_file_flags=0;
define_value=NULL;
comment_init_state=INITIAL;
gnu_att_depth=0;
gnu_typ_depth=0;
push_past=0;
SeenComment((char*)3);
}
%}
%%
/* Comments, could be embedded in a preprocessor directive. */
<INITIAL>("/*"|"//") { comment_init_state = INITIAL ; BEGIN(yytext[1]=='*'?START_COMMENT:START_COMMENT_CPP); }
<CPP_START>("/*"|"//") { comment_init_state = CPP_START ; BEGIN(yytext[1]=='*'?START_COMMENT:START_COMMENT_CPP); }
<CPP>("/*"|"//") { comment_init_state = CPP ; BEGIN(yytext[1]=='*'?START_COMMENT:START_COMMENT_CPP); }
<CPP_DEFINE>("/*"|"//") { comment_init_state = CPP_DEFINE ; BEGIN(yytext[1]=='*'?START_COMMENT:START_COMMENT_CPP); }
<CPP_INCLUDE>("/*"|"//") { comment_init_state = CPP_INCLUDE ; BEGIN(yytext[1]=='*'?START_COMMENT:START_COMMENT_CPP); }
<CPP_DEFINE_ARGP>("/*"|"//") { comment_init_state = CPP_DEFINE_ARGP; BEGIN(yytext[1]=='*'?START_COMMENT:START_COMMENT_CPP); }
<CPP_DEFINE_ARGS>("/*"|"//") { comment_init_state = CPP_DEFINE_ARGS; BEGIN(yytext[1]=='*'?START_COMMENT:START_COMMENT_CPP); }
<CPP_DEFINE_BODY>("/*"|"//") { comment_init_state = CPP_DEFINE_BODY; BEGIN(yytext[1]=='*'?START_COMMENT:START_COMMENT_CPP); }
<CPP_INC_FILE>("/*"|"//") { comment_init_state = CPP_INC_FILE ; BEGIN(yytext[1]=='*'?START_COMMENT:START_COMMENT_CPP); }
<CPP_INC_FLAGS>("/*"|"//") { comment_init_state = CPP_INC_FLAGS ; BEGIN(yytext[1]=='*'?START_COMMENT:START_COMMENT_CPP); }
<START_COMMENT>"*"+ { BEGIN(SPECIAL_COMMENT); }
<START_COMMENT>"+"+ { BEGIN(SPECIAL_COMMENT); }
<START_COMMENT>[*+ \t]*"*/" { BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<START_COMMENT>{N} { if(option_all_comments) SeenComment(yytext); parse_line++;
if(option_all_comments) BEGIN(SPECIAL_COMMENT); else BEGIN(COMMENT); }
<START_COMMENT>[^*+] { if(option_all_comments) SeenComment(yytext);
if(option_all_comments) BEGIN(SPECIAL_COMMENT); else BEGIN(COMMENT); }
<START_COMMENT_CPP>"*"+ { BEGIN(SPECIAL_COMMENT_CPP); }
<START_COMMENT_CPP>"+"+ { BEGIN(SPECIAL_COMMENT_CPP); }
<START_COMMENT_CPP>{N} { if(comment_init_state==CPP_INCLUDE || comment_init_state==CPP_DEFINE) comment_init_state=INITIAL;
parse_line++; BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<START_COMMENT_CPP>[^*+] { if(option_all_comments) BEGIN(SPECIAL_COMMENT_CPP); else BEGIN(COMMENT_CPP); }
<COMMENT>{N} { parse_line++; }
<COMMENT>. { }
<COMMENT>[+*]+/"*/" { if(option_warn&COMMENT) fprintf(stderr,"%s:%d: Warning unbalanced cxref comment; starts simple, ends special.\n",parse_file,parse_line); }
<COMMENT>"*/" { BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<COMMENT_CPP>.*{N} { if(comment_init_state==CPP_INCLUDE || comment_init_state==CPP_DEFINE) comment_init_state=INITIAL;
parse_line++; BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<SPECIAL_COMMENT>{N} { if(!option_no_comments) SeenComment(yytext); parse_line++; }
<SPECIAL_COMMENT>{N}{W}*[+*|:]/({W}|{N}) { parse_line++;
if(option_block_comments) yytext[0]='\n',yytext[1]=0;
if(!option_no_comments) SeenComment(yytext); }
<SPECIAL_COMMENT>[^\r\n*+]+ { if(!option_no_comments) SeenComment(yytext); }
<SPECIAL_COMMENT>. { if(!option_no_comments) SeenComment(yytext); }
<SPECIAL_COMMENT>{W}*"*"+"*/" { if(!option_no_comments) SeenComment((char*)0);
BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<SPECIAL_COMMENT>{W}*"+"+"*/" { if(!option_no_comments) SeenComment((char*)1);
if(!in_header && comment_init_state==CPP_DEFINE_ARGS) SeenDefineFuncArgComment();
if(!in_header && comment_init_state==CPP_DEFINE_BODY) SeenDefineComment();
if(!in_header && comment_init_state==CPP_INCLUDE) SeenIncludeComment();
BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<SPECIAL_COMMENT>"*/" { if(!option_all_comments && option_warn&COMMENT)
fprintf(stderr,"%s:%d: Warning unbalanced cxref comment; starts special, ends simple.\n",parse_file,parse_line);
if(option_all_comments) SeenComment((char*)2); else if(!option_no_comments) SeenComment((char*)1);
if(!in_header && comment_init_state==CPP_DEFINE_ARGS) SeenDefineFuncArgComment();
if(!in_header && comment_init_state==CPP_DEFINE_BODY) SeenDefineComment();
if(!in_header && comment_init_state==CPP_INCLUDE) SeenIncludeComment();
BEGIN(comment_init_state); while(push_past) {push_past--;unput(yylval[push_past]);} }
<SPECIAL_COMMENT_CPP>[^\r\